package org.gwt.server.redes;
import smile.Network;

public class Problema {
	
	private NetBuilder builder;
	private Network net;
	private int problemNumber;
	
	public Problema(int num){
		problemNumber=num;
		builder = new NetBuilder(num);
		net=builder.getNetwork();		
	}
	
	public String searchElement(String s){
		System.out.println("SEARCH "+s);
		String nodesIds[]=net.getAllNodeIds();
		String selectNodeID = "";
		String returnMsg="",newName="";
		int flag=0;
		for(String id : nodesIds){
			if(!id.startsWith("H")) continue;
			if (net.getNodeName(id).contains(s.substring(s.indexOf("(")))){
				selectNodeID=id;		
				flag=1;
				break;
			}
		}
		if(flag==0) returnMsg="ESO NO EXISTE HIJO";
		else{ 
			returnMsg="x";
			net.setEvidence(selectNodeID,"TRUE");
			net.setNodeName(selectNodeID,s.substring(0,s.indexOf("("))+"="+s.substring(s.indexOf("(")));
			net.updateBeliefs();
		}		
		return returnMsg;
	}
	
	public void writeFile(){
		System.out.println("writ");
		net.writeFile("Problema"+problemNumber+".xdsl");
	}

}
